package com.redstars.generate.controller;


import com.redstars.generate.page.PageResult;
import com.redstars.generate.result.Result;
import com.redstars.generate.vo.SysProjectConfigVo;
import lombok.AllArgsConstructor;
import com.redstars.generate.service.SysProjectConfigService;
import com.redstars.generate.query.SysProjectConfigQuery;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

/**
* 项目基础配置
*
* @author zhouhx 
* @since 1.0.0 2022-10-14
*/
@RestController
@RequestMapping("gen/projectconfig")
@AllArgsConstructor
public class SysProjectConfigController {
    private final SysProjectConfigService sysProjectConfigService;

    @GetMapping("page")
    public Result<PageResult<SysProjectConfigVo>> page(@Valid SysProjectConfigQuery query){
        PageResult<SysProjectConfigVo> page = sysProjectConfigService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    public Result<SysProjectConfigVo> detail(@PathVariable("id") Long id){
        SysProjectConfigVo detail = sysProjectConfigService.detail(id);

        return Result.ok(detail);
    }

    @PostMapping
    public Result<String> save(@RequestBody SysProjectConfigVo vo){
        sysProjectConfigService.save(vo);

        return Result.ok();
    }

    @PutMapping
    public Result<String> update(@RequestBody @Valid SysProjectConfigVo vo){
        sysProjectConfigService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    public Result<String> delete(@RequestBody List<Long> idList){
        sysProjectConfigService.delete(idList);

        return Result.ok();
    }

    @GetMapping("project/{id}")
    public Result<SysProjectConfigVo> detailByProjectId(@PathVariable("id") Long projectId){
        SysProjectConfigVo detail = sysProjectConfigService.detailByProjectId(projectId);

        return Result.ok(detail);
    }
}